package com.zry.traced.presenter

import android.content.Context
import android.os.AsyncTask.execute
import android.util.Log
import com.zry.traced.been.LongAndShortCode
import com.zry.traced.retrofit.ApiSupport
import com.zry.traced.retrofit.ShowUserView
import com.zry.traced.retrofit.dialog.ProgressSubscriber
import com.zry.traced.utils.ToastUtil
import retrofit2.http.Query


class HttpServer(private val showUserView: ShowUserView) : ApiSupport {
    /**
     * 用户登录
     */
    fun loginApi(username: String, password: String, juris: String, context: Context) {
        execute(api.loginApi(username, password, juris), ProgressSubscriber({ httpResponse ->
            Log.e("TAG", httpResponse.toString())
            showUserView.toMainActivity(0, httpResponse)
        }, context))
    }

    /**
     * 获取产品信息
     */
    fun getProductList(enterpriseId: String, context: Context) {
        execute(api.GetProductList(enterpriseId), ProgressSubscriber({ productInfoList ->
            Log.e("TAG", productInfoList.toString())
            showUserView.toMainActivity(1, productInfoList)
        }, context))
    }

    /**
     * 获取生产批次
     */
    fun getBatchByProductId(productId: String, context: Context) {
        execute(api.GetBatchByProductId(productId), ProgressSubscriber({ batchInfoList ->
            Log.e("TAG", batchInfoList.toString())
            showUserView.toMainActivity(2, batchInfoList)
        }, context))
    }

    /**
     * 获取生产线
     */
    fun getProductionLine(enterpriseId: String, context: Context) {
        execute(api.GetProductionLine(enterpriseId), ProgressSubscriber({ productLineList ->
            Log.e("TAG", productLineList.toString())
            showUserView.toMainActivity(3, productLineList)
        }, context))
    }

    /**
     * 获取装箱单位列表
     */
    fun getPackList(context: Context) {
        execute(api.GetPackList(), ProgressSubscriber({ packList ->
            Log.e("TAG", packList.toString())
            showUserView.toMainActivity(4, packList)
        }, context))
    }


    /**
     * 获取长追溯码
     */
    fun getLongTraceCode(shortCode: String, pid: String, stype: String, parentCode: String, context: Context) {
        execute(api.GetCodeID(shortCode, pid, stype, parentCode), ProgressSubscriber({ resultCode ->
            resultCode.shortCode = shortCode
            showUserView.toMainActivity(5, resultCode)
        }, context))
    }

    /**
     * 获取长流通码
     */
    fun getLongCirculationCode(shortCode: String, pid: String, stype: String, orderType: String,
                               parentCode: String, context: Context) {
        execute(api.GetFlowCode(shortCode, pid, stype, orderType, parentCode), ProgressSubscriber({ resultFlowCode ->
            resultFlowCode.shortCode = shortCode
            showUserView.toMainActivity(6, resultFlowCode)
        }, context))
    }

    /**
     * 批量打包
     */
    fun postAddLiangFlow(level: String, ProductID: String, UnitID: String, SonCodeNum: String, CodeS: String, UserID: String, EnterpriseID: String, context: Context) {
        execute(api.AddLiangFlow(level, ProductID, UnitID, SonCodeNum, CodeS, UserID, EnterpriseID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(7, resultData)
        }, context))
    }


    /**
     * 获取打包记录
     */
    fun getFlowCodeList(EnterpriseID: String, CreateUserID: String, pageIndex: Int, pageSize: Int, context: Context) {
        execute(api.GetFlowCodeList(EnterpriseID, CreateUserID, pageIndex, pageSize), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(8, resultData)
        }, context))
    }

    /**
     * 获取打包详情
     */
    fun getFlowCodeDetailList(FlowCodeID: String, context: Context) {
        execute(api.GetFlowCodeDetailList(FlowCodeID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(9, resultData)
        }, context))
    }


    /**
     * 号段打包
     */
    fun addDuanFlow(level: String, ProductID: String, UnitID: String, SonCodeNum: String, MaxCode: String, MinCode: String, UserID: String, EnterpriseID: String, context: Context) {
        execute(api.AddDuanFlow(level, ProductID, UnitID, SonCodeNum, MaxCode, MinCode, UserID, EnterpriseID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(10, resultData)
        }, context))
    }

    /**
     * 获取订单列表
     */
    fun getStoreOrderList(EnterpriseID: String, pageIndex: Int, pageSize: Int, context: Context) {
        execute(api.GetStoreOrderList(EnterpriseID, pageIndex, pageSize), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(11, resultData)
        }, context))
    }

    /**
     * 批量入库
     */
    fun addLiangStore(OrderID: String, CodeS: String, UserID: String, context: Context) {
        execute(api.AddLiangStore(OrderID, CodeS, UserID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(12, resultData)
        }, context))
    }

    /**
     * 号段入库
     */
    fun addDuanStore(OrderID: String, MaxCode: String, MinCode: String, UserID: String, context: Context) {
        execute(api.AddDuanStore(OrderID, MaxCode, MinCode, UserID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(13, resultData)
        }, context))
    }

    /**
     * 入库记录
     */
    fun getStoreDetailList(CreateUserID: String, pageIndex: Int, pageSize: Int, context: Context) {
        execute(api.GetStoreDetailList(CreateUserID, pageIndex, pageSize), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(14, resultData)
        }, context))
    }

    /**
     * 入库记录详情
     */
    fun getStoreDetailInfo(DetailID: String, context: Context) {
        execute(api.GetStoreDetailInfo(DetailID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(15, resultData)
        }, context))
    }

    /**
     * 出库订单列表
     */
    fun getOutStockList(EnterpriseID: String, pageIndex: Int, pageSize: Int, context: Context) {
        execute(api.GetOutStockList(EnterpriseID, pageIndex, pageSize), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(16, resultData)
        }, context))
    }

    /**
     * 批量出库
     */
    fun addLiangOutStockDetail(OutStockID: String, ProductID: String, OutLevel: String, CodeS: String,
                               CreateUserID: String, EnterpriseID: String, context: Context) {
        execute(api.AddLiangOutStockDetail(OutStockID, ProductID, OutLevel, CodeS, CreateUserID, EnterpriseID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(17, resultData)
        }, context))
    }

    /**
     * 号段出库
     */

    fun addDuanOutStockDetail(OutStockID: String, ProductID: String, OutLevel: String, MinCode: String, MaxCode: String,
                              CreateUserID: String, EnterpriseID: String, context: Context) {
        execute(api.AddDuanOutStockDetail(OutStockID, ProductID, OutLevel, MinCode, MaxCode, CreateUserID, EnterpriseID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(18, resultData)
        }, context))
    }

    /**
     * 获取出库记录列表
     */
    fun getOutDetailList(CreateUserID: String, pageIndex: Int, pageSize: Int, context: Context) {
        execute(api.GetOutDetailList(CreateUserID, pageIndex, pageSize), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(19, resultData)
        }, context))
    }


    /**
     * 获取出库记录详情
     */
    fun getOutDetailInfo(DetailID: String, context: Context) {
        execute(api.GetOutDetailInfo(DetailID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(20, resultData)
        }, context))
    }

    /**
     * 根据流通吗获取产品信息
     */
    fun getFlowCodeInfo(CodeID: String, stype: Int, context: Context) {
        execute(api.GetFlowCodeInfo(CodeID, stype), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(21, resultData)
        }, context))
    }

    /**
     * 补码入箱
     */
    fun complementFlow(CodeID: String, SonCode: String, EnterpriseID: String, CreateUserID: String, context: Context) {
        execute(api.ComplementFlow(CodeID, SonCode, EnterpriseID, CreateUserID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(22, resultData)
        }, context))
    }

    /**
     * 拆码出箱
     */
    fun dismantlingFlow(CodeID: String, SonCode: String, EnterpriseID: String, CreateUserID: String, context: Context) {
        execute(api.DismantlingFlow(CodeID, SonCode, EnterpriseID, CreateUserID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(23, resultData)
        }, context))
    }

    /**
     * 补码、拆码记录列表
     */

    fun getFlowRecordList(CreateUserID: String, EnterpriseID: String, StateID: String, pageIndex: Int, pageSize: Int, context: Context) {
        execute(api.GetFlowRecordList(CreateUserID, EnterpriseID, StateID, pageIndex, pageSize), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(24, resultData)
        }, context))
    }

    /**
     * 补码、拆码详情
     */
    fun getFlowRecordInfo(RecordID: String, context: Context) {
        execute(api.GetFlowRecordInfo(RecordID), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(25, resultData)
        }, context))
    }

    /**
     * 判断当前是否有新版本
     */
    fun checkApp(vNumber: String, context: Context) {
        execute(api.checkApp(vNumber, "PDA"), ProgressSubscriber({ resultData ->
            showUserView.toMainActivity(26, resultData)
        }, context))
    }

}

